import { IPSAppView } from '../../app/view/ipsapp-view';
import { IPSNavigateContext } from '../ipsnavigate-context';
import { IPSNavigateParam } from '../ipsnavigate-param';
import { IPSDEForm } from './ipsdeform';
import { IPSDEFormDRUIPart } from './ipsdeform-druipart';
import { IPSDEFormItemUpdate } from './ipsdeform-item-update';
import { PSDEFormDetailImpl } from './psdeform-detail-impl';

export class PSDEFormDRUIPartImpl extends PSDEFormDetailImpl implements IPSDEFormDRUIPart {
  protected psappview: IPSAppView | null = null;

  getPSAppView(): IPSAppView | null {
    if (this.psappview != null) return this.psappview;
    const value = this.M.getPSAppView;
    if (value == null) {
      return null;
    }
    this.psappview = this.getPSModel4('app.view.IPSAppView', value, 'getPSAppView') as IPSAppView;
    return this.psappview;
  }

  get psAppView(): IPSAppView | null {
    return this.getPSAppView();
  }

  getPSAppViewMust(): IPSAppView {
    const value = this.getPSAppView();
    if (value == null) {
      throw new Error('未指定嵌入视图');
    }
    return value;
  }

  protected psdeformitemupdate: IPSDEFormItemUpdate | null = null;

  getPSDEFormItemUpdate(): IPSDEFormItemUpdate | null {
    if (this.psdeformitemupdate != null) return this.psdeformitemupdate;
    const value = this.M.getPSDEFormItemUpdate;
    if (value == null) {
      return null;
    }
    const ipsdeform = this.getParentPSModelObject('control.form.IPSDEForm') as IPSDEForm;
    if (ipsdeform != null) {
      this.psdeformitemupdate = ipsdeform.findPSDEFormItemUpdate(value);
    }
    return this.psdeformitemupdate;
  }

  get psDEFormItemUpdate(): IPSDEFormItemUpdate | null {
    return this.getPSDEFormItemUpdate();
  }

  getPSDEFormItemUpdateMust(): IPSDEFormItemUpdate {
    const value = this.getPSDEFormItemUpdate();
    if (value == null) {
      throw new Error('未指定调用表单项更新');
    }
    return value;
  }

  protected psnavigatecontexts: IPSNavigateContext[] | null = null;

  getPSNavigateContexts(): IPSNavigateContext[] | null {
    if (this.psnavigatecontexts == null) {
      this.psnavigatecontexts = this.fillChildListModel(this.M.getPSNavigateContexts, 'control.IPSNavigateContext') as IPSNavigateContext[];
    }
    return this.psnavigatecontexts;
  }

  get psNavigateContexts(): IPSNavigateContext[] | null {
    return this.getPSNavigateContexts();
  }

  findPSNavigateContext(objKey: any): IPSNavigateContext | null {
    return this.getPSModel5('control.IPSNavigateContext', this.getPSNavigateContexts(), objKey) as IPSNavigateContext;
  }

  protected psnavigateparams: IPSNavigateParam[] | null = null;

  getPSNavigateParams(): IPSNavigateParam[] | null {
    if (this.psnavigateparams == null) {
      this.psnavigateparams = this.fillChildListModel(this.M.getPSNavigateParams, 'control.IPSNavigateParam') as IPSNavigateParam[];
    }
    return this.psnavigateparams;
  }

  get psNavigateParams(): IPSNavigateParam[] | null {
    return this.getPSNavigateParams();
  }

  findPSNavigateParam(objKey: any): IPSNavigateParam | null {
    return this.getPSModel5('control.IPSNavigateParam', this.getPSNavigateParams(), objKey) as IPSNavigateParam;
  }

  get paramItem(): string {
    return this.M.paramItem;
  }

  get parentDataJO(): IModel {
    return this.M.parentDataJO;
  }

  get refreshItems(): string {
    return this.M.refreshItems;
  }

  get needSave(): boolean {
    return this.M.needSave;
  }

  get refreshItemsSetParamOnly(): boolean {
    return this.M.refreshItemsSetParamOnly;
  }

  get cls(): string {
    return 'PSDEFormDRUIPartImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSNavigateParamContainer' || cls == 'control.form.IPSDEFormDRUIPart') return true;
    return super.instanceof(cls);
  }
}
